package com.yuhuihui.common.utils.excel.export;


import com.yuhuihui.common.utils.excel.export.parameters.ExcelExportSheetParameter;
import org.apache.poi.ss.usermodel.Sheet;

import java.util.Set;

/**
 * 导出行可运行
 *
 * @author yuhh
 * @date 2022-08-22 16:44:27
 * @see Runnable
 */
public class ExportRowRunnable<T> implements Runnable {

    /**
     * 工作区
     */
    private Sheet sheet;

    /**
     * 数据列表
     */
    private T data;

    /**
     * 行数
     */
    private Integer row;

    /**
     * code长度
     */
    private Integer codeSize;

    /**
     * 替换值key列表
     */
    private Set<String> replaceInfoKeys;

    /**
     * 合并行列表
     */
    private Set<String> mergeLineSet;

    /**
     * sheet参数
     */
    private ExcelExportSheetParameter<T> parameter;

    public ExportRowRunnable(Sheet sheet, T data, int codeSize, int row, Set<String> replaceInfoKeys,
                             Set<String> mergeLineSet, ExcelExportSheetParameter<T> parameter){
        this.sheet = sheet;
        this.data = data;
        this.codeSize = codeSize;
        this.row = row;
        this.replaceInfoKeys = replaceInfoKeys;
        this.mergeLineSet = mergeLineSet;
        this.parameter = parameter;
    }

    private ExportRowRunnable(){

    }

    @Override
    public void run() {
        try {
            int[] mergeLineNum = new int[codeSize];
            ExcelExport.exportRow(sheet, data, codeSize, row, replaceInfoKeys, mergeLineSet, parameter, mergeLineNum);
        } catch (Exception e){
            throw new RuntimeException("多线程excel导出行数据出现异常", e);
        }
    }

    public Sheet getSheet() {
        return sheet;
    }

    public ExportRowRunnable<T> setSheet(Sheet sheet) {
        this.sheet = sheet;
        return this;
    }

    public T getData() {
        return data;
    }

    public ExportRowRunnable<T> setData(T data) {
        this.data = data;
        return this;
    }

    public Integer getRow() {
        return row;
    }

    public ExportRowRunnable<T> setRow(Integer row) {
        this.row = row;
        return this;
    }

    public Integer getCodeSize() {
        return codeSize;
    }

    public ExportRowRunnable<T> setCodeSize(Integer codeSize) {
        this.codeSize = codeSize;
        return this;
    }

    public Set<String> getReplaceInfoKeys() {
        return replaceInfoKeys;
    }

    public ExportRowRunnable<T> setReplaceInfoKeys(Set<String> replaceInfoKeys) {
        this.replaceInfoKeys = replaceInfoKeys;
        return this;
    }

    public Set<String> getMergeLineSet() {
        return mergeLineSet;
    }

    public ExportRowRunnable<T> setMergeLineSet(Set<String> mergeLineSet) {
        this.mergeLineSet = mergeLineSet;
        return this;
    }

    public ExcelExportSheetParameter<T> getParameter() {
        return parameter;
    }

    public ExportRowRunnable<T> setParameter(ExcelExportSheetParameter<T> parameter) {
        this.parameter = parameter;
        return this;
    }
}
